package org.budo.jdbc.driver.resultset.impl;

import java.sql.ResultSetMetaData;
import java.util.Map;

import org.budo.jdbc.driver.BudoJdbcResultSetMetaData;

import lombok.NoArgsConstructor;

/**
 * 多列多行结果集
 * 
 * @author lmw
 */
@NoArgsConstructor
public class MapArrayResultSet extends ObjectArrayResultSet<Map<?,?>> {
    public MapArrayResultSet(String[] columnNames, Map<?,?>[] valueArray) {
        this(new BudoJdbcResultSetMetaData(columnNames), valueArray);
    }

    public MapArrayResultSet(ResultSetMetaData metaData, Object[] valueArray) {
        this.setMetaData(metaData);
        this.setValueArray((Map<?, ?>[]) valueArray);
    }

    @Override
    protected Object getColumnValueRaw(String columnLabel) {
        int rowNumber = this.getRowNumber();
        Map<?,?> map = (Map<?,?>) this.getValueArray()[rowNumber];
        Object value = map.get(columnLabel);

        if (null == value) {
            this.setLastValueWasNull(true);
        }

        return value;
    }
}
